package com.bmslz.monitor.base.dto;

import com.baomidou.mybatisplus.annotation.IdType;
import com.baomidou.mybatisplus.annotation.TableId;
import com.bmslz.monitor.base.util.StringUtils;
import com.bmslz.monitor.base.config.excep.MyException;
import com.bmslz.monitor.base.entity.AlarmModelRule;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;

import java.util.List;

/**
 * @Description: 新增或者修改入参
 * @Author: bobo
 * @Date: 2025-08-10
 * @Version: V1.0
 */
@Data
public class AlarmModelSaveDto {

    /**
     * id
     */
    @TableId(type = IdType.ASSIGN_ID)
    @ApiModelProperty(value = "id")
    private String id;
    /**
     * 模板编号
     */
    @ApiModelProperty(value = "模板编号")
    private String modelNo;
    /**
     * 关联监控模型ID
     */
    @ApiModelProperty(value = "关联监控模型ID")
    private String monitorModelId;
    /**
     * 模板名称
     */
    @ApiModelProperty(value = "模板名称")
    private String name;
    /**
     * 通知类型 1 阿里云短信 2.邮箱 3.钉钉 4.公众号 5.http
     */
    @ApiModelProperty(value = "通知类型 1 阿里云短信 2.邮箱 3.钉钉 4.公众号 5.http")
    private String notifyType;
    /**
     * 通知参数
     */
    @ApiModelProperty(value = "通知参数")
    private String notifyData;
    /**
     * 详细规则
     */
    @ApiModelProperty(value = "详细规则")
    private List<AlarmModelRule> rules;

    public void baseCheck() {
        if (StringUtils.isEmpty(modelNo)) {
            throw new MyException(500, "模板编号不能为空");
        }
        if (StringUtils.isEmpty(monitorModelId)) {
            throw new MyException(500, "关联监控模型编号不能为空");
        }
        if (StringUtils.isEmpty(name)) {
            throw new MyException(500, "模板名称不能为空");
        }
        if (StringUtils.isEmpty(notifyType)) {
            throw new MyException(500, "通知类型不能为空");
        }
        if (StringUtils.isEmpty(notifyData)) {
            throw new MyException(500, "通知参数不能为空");
        }
        if (rules == null || rules.size() < 1) {
            throw new MyException(500, "详细规则不能为空");
        }
    }

    public void checkByAdd() {
        baseCheck();
    }

    public void checkByEdit() {
        baseCheck();
        if (StringUtils.isEmpty(id)) {
            throw new MyException(500, "id不能为空");
        }
    }
}
